'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
var app = getApp();
var wxpay = require('../../../../static/utils/pay.js');
exports.default = Page({
    data: {
        userApply: false,
        userMoney: false,
        v2AgentInfo: ''
    },
    onShow: function onShow(e) {
        var that = this;
        that.getV2AgentInfo();
        that.getAgentUserInfo();
    },
    getV2AgentInfo: function getV2AgentInfo() {
        var that = this;
        var token = wx.getStorageSync('__appUserInfo').token;
        wx.GET(wx.URL.v2agentinfos, { token: token }).then(function (res) {
            console.log('2222', res);
            if (res.code == 0) {
                that.setData({ v2AgentInfo: res.data });
            }
        });
    },
    getAgentUserInfo: function getAgentUserInfo() {
        var that = this;
        var token = wx.getStorageSync('__appUserInfo').token;
        wx.GET(wx.URL.agentinfos, { token: token }).then(function (res) {
            console.log('111', res);
            if (res.code == 0) {
                that.setData({ agentInfo: res.data });
            }
        });
    },
    formSubmit: function formSubmit(e) {
        var that = this;
        var phone = e.detail.value.phone;
        var wechat = e.detail.value.wechat;
        var upAgent = wx.getStorageSync("__appAgentUser");
        var token = wx.getStorageSync('__appUserInfo').token;
        var postData = {};
        if (!phone) {
            wx.showModal({
                content: '请输入您的手机号码',
                confirmColor: '#de6360',
                showCancel: false
            });
            return;
        } else if (!wechat) {
            wx.showModal({
                content: '请输入您的微信号（非手机号码）',
                confirmColor: '#de6360',
                showCancel: false
            });
            return;
        } else {
            postData.token = token;
            postData.phone = phone;
            postData.wechat = wechat;
            if (upAgent) {
                postData.uid = upAgent;
            }
            wx.GET(wx.URL.v2agentapply, postData).then(function (res) {
                console.log(res);
                if (res.code == 0) {
                    wx.showToast({ title: '信息提交成功' });
                    that.getV2AgentInfo();
                    that.getAgentUserInfo();
                } else {
                    wx.showModal({
                        content: res.msg,
                        showCancel: false
                    });
                }
            });
        }
    },
    agentProtocolTap: function agentProtocolTap() {
        
        var data = this.data.agentInfo;
        if (data) {
            wx.navigateTo({
                url: "/pages/pages/user/agent/protocol?id=" + data.level
            });
        } else {
            wx.navigateTo({
                url: "/pages/pages/user/agent/protocol?id=1"
            });
        }
    },
    getPaypalTap: function getPaypalTap() {
        var that = this;
        var data = that.data.v2AgentInfo;
        var nextAction = {
            ctype: 6,
            id: data.order,
            ptype: 0
        };
        wxpay.wxpay(app, data.money, 0, -1, nextAction);
    },
    getMemberProfit: function getMemberProfit() {
        wx.navigateTo({
            url: "/pages/pages/user/agent/profit"
        });
    },
    getMoneyBack: function getMoneyBack() {
        var token = wx.getStorageSync('__appUserInfo').token;
        wx.showModal({
            title: '代理提示',
            content: '退回保证金后将取消您的代理身份，并且您下级的客户将会被清除。客户数据一旦被清除将不可恢复，是否确定申请退回保证金？',
            success: function success(res) {
                if (res.confirm) {
                    wx.GET(wx.URL.v2agnetmoney, { token: token }).then(function (res) {
                        console.log(res);
                        if (res.code == 0) {
                            wx.showModal({
                                content: '保证金申请退回成功，请等待客服审核。如有疑问请联系我们的客服人员。',
                                showCancel: false
                            });
                        } else if (res.code == 408) {
                            wx.showModal({
                                content: '已经申请过退回，请等待客服审核。如有疑问请联系我们的客服人员。',
                                showCancel: false
                            });
                        } else {
                            wx.showModal({
                                content: res.msg,
                                showCancel: false
                            });
                        }
                    });
                }
            }
        });
    },
    onShareAppMessage: function onShareAppMessage() {
        var that = this;
        var data = that.data.agentInfo;
        return {
            title: data.name + '向您推荐泰国吃喝玩乐',
            path: '/pages/pages/home/home?uid=' + data.id,
            success: function success(res) {
                // 转发成功
            },
            fail: function fail(res) {
                // 转发失败
            }
        };
    },
    navigateBack: function navigateBack() {
        wx.navigateBack();
    },
    getHomeTap: function getHomeTap() {
        wx.switchTab({
          url: "/pages/pages/home/home"
        });
    },

});